#include <bits/stdc++.h>
using namespace std ;
const int N=1e6+10;
int c2[N];
struct car{
    int d,v,a;
};
car c[N];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t,n,m,l,vx;
    int p=0;
    scanf("%d",&t);
    while(t){
        scanf("%d%d%d%d",&n,&m,&l,&vx);
        for(int i=1;i<=n;i++) scanf("%d%d%d",&c[i].d,&c[i].v,&c[i].a);
        for(int i=1;i<=m;i++) scanf("%d",&c2[i]);
        for(int i=1;i<=n;i++){
            if(c[i].v>vx && c[i].a==0) p++;
        }
        t--;
    }
    cout<<p<<" "<<m-1<<endl;
    return 0;
}
